<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>管理员账号</title>
		<link href="plugin/date/date.css" rel="stylesheet">
		<link href="bootstrap/css/bootstrap3.min.css" rel="stylesheet">
		<link href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
		<script src="js/jquery.min.js"></script>
		<link rel="stylesheet" href="css/nav.css" />
		<style>
			.form-group-update {
				margin-right: 2%;
			}
			.imgsBox  {display: inline-block; margin-right: 5px; margin-top: 5px;}
			.imgsBox img{ width: 100px;}
		</style>
	</head>
	<body>
		<!--导航-->
	    <nav class="navbar navbar-inverse">
	      <div class="container-fluid">
	        <div class="navbar-header">
	          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-2">
	            <span class="sr-only">Toggle navigation</span>
	            <span class="icon-bar"></span>
	            <span class="icon-bar"></span>
	            <span class="icon-bar"></span>
	          </button>
		          	<a class="navbar-brand" href=""><img src="images/admin_logo.png" alt=""></a>
	        </div>

	        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-2">
	          <ul class="nav navbar-nav" id="nav">

	          </ul>
	          <ul class="nav navbar-nav navbar-right">
	            <li class="dropdown">
	              <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">欢迎您：<span id="uname"></span><span class="caret"></span></a>
	              <ul class="dropdown-menu" role="menu">
	                <li><a href="change_pass.html">修改密码</a></li>
	                <li><a id="loginOut" href="#">退出登陆</a></li>
	              </ul>
	            </li>
	          </ul>
	        </div>
	      </div>
	    </nav>
		<div class="container-fluid">
			<div class="row bcert-box">
				<ol class="breadcrumb">
				  <li><a href="javascript:;">主页</a></li>
				  <li>网站设置</li>
				  <li class="active">管理员账号</li>
				</ol>
				<button type="button" class="btn btn-primary btn-success" data-toggle="modal" id="addBtn" data-target=""><span class="glyphicon glyphicon-plus" aria-hidden="true"></span>&nbsp;添加管理员账号</button>
				<div class="table">
		          	<table class="table table-bordered table-striped" id="integralList">

		          	</table>
		        </div>
				<!-- 分页 -->
		        <nav aria-label="...">
		            <div class="">
		            	<span id="pageNum">共&nbsp;<strong></strong>&nbsp;页&nbsp;/&nbsp;</span><span id="totalNum">&nbsp;<strong>0</strong>&nbsp;条数据</span>
		            </div>
		            <ul id="example"></ul>
		        </nav>
		    </div>
		</div>

		<div class="modal fade" tabindex="-1" id="editRole" role="dialog" aria-labelledby="">
			<div class="modal-dialog modal-lg" role="document">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span>
						</button>
							<h4 class="modal-title" id="myLargeModalLabel">详细</h4>
					</div>
					<div class="modal-body" style="overflow:auto">
						 <div class="form-group">
							 <label class="col-sm-2 control-label goods-lb-l">管理员名称</label>
							 <div class="col-sm-10 goods-lb-r">
								 <input type="text" class="form-control" id="adminName" placeholder="管理员名称">
							 </div>
						 </div>
						 <div class="form-group">
							 <label class="col-sm-2 control-label goods-lb-l">管理员密码</label>
							 <div class="col-sm-10 goods-lb-r">
								 <input type="password" class="form-control" id="adminPassword" placeholder="管理员密码">
							 </div>
						 </div>
						 <div class="form-group">
							<label class="col-sm-2 control-label goods-lb-l">角色类型</label>
							<div class="col-sm-10 goods-lb-r">
								<select class="form-control drop-down" id="roleId">
								   <!-- <option value="0">请选择套餐</option>
								   <option value="1">套餐1</option>
								   <option value="2">套餐2</option>
								   <option value="3">套餐3</option> -->
								</select>
							</div>
						</div>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
						<button type="button" class="btn btn-primary" id="entBtns">确认提交</button>
					</div>
				</div>
				<!-- /.modal-content -->
			</div>
			<!-- /.modal-dialog -->
		</div>
	</body>
</html>
<script type="text/javascript" src="plugin/layer/layer.js"></script>
<script type="text/javascript" src="js/cookie.js"></script>
<script type="text/javascript" src="js/common.js"></script>
<script type="text/javascript" src="js/ajax.js"></script>
<script src="js/md5.min.js"></script>
 <script type="text/javascript" src="js/bootstrap-paginator.js"></script>
<script type="text/javascript" src="bootstrap/js/bootstrap.min.js"></script>
<script>
	$(document).ready(function() {
		tableList()
		roleList()
	});
	var pageUrls =  serverURL + '/platform/queryAdminList';
	var permissionsUrls  = ''
	//分页
    function tableList(){
  	  data = {
  		  'page': page,
  		  'pageSize': pagesize
  	  }
  	  data.page = 1
  	  ajax(
  		  pageUrls,
  		  data,
  		  pageNumList,
  		  'post',
  		  'json'
  	  )
    }
	//数据渲染
    function OpendList(res){
      var result = '';
      $('#integralList').empty();
      $('#integralList').append(
        '<tr>' +
        '<th>管理员id</th>' +
        '<th>管理员名称</th>' +
		'<th>角色名称</th>' +
		'<th>上次登陆时间</th>' +
		'<th>登录次数</th>' +
		'<th>操作</th>' +
    	'</tr>'
      );
		for (var i = 0; i < res.data.list.length; i++) {
			result +=
	           	'<tr>'+
	             '<td>'+ res.data.list[i].adminId +'</td>'+
	             '<td>'+ res.data.list[i].adminName +'</td>'+
				 '<td>'+ res.data.list[i].roleName +'</td>'+
	             '<td>'+ res.data.list[i].adminLoginTime +'</td>'+
				 '<td>'+ res.data.list[i].adminLoginNum +'</td>'+
		   		 '<td class="text-center"><button data-id="'+ res.data.list[i].adminId +'" id="delRole" class="btn btn-danger btn-sm" onclick="delRole('+ res.data.list[i].adminId +')">删除</button>&nbsp;&nbsp;&nbsp;<button data-id="'+ res.data.list[i].adminId +'" class="btn btn-primary btn-sm editRole">编辑</button></td>'+
	            '</td></tr>'
		}
      $('#integralList').append(result)
    }
	//删除
	function delRole(id){
		layer.confirm('确定要删除吗？', {
			btn: ['确认','取消'] //按钮
		}, function(){
			var data = {
				'adminId':id
			}
			var cbk = function(){
				tableList()
			}
			ajax(
	    		serverURL + '/platform/deleteAdminById',
	    		data,
	    		cbk,
	    		'post',
	    		'json'
	    	)
		}, function(){
		});

	}

	//功能组

	//添加
	$('#addBtn').click(function(){
		$('#entBtns').attr('data-id','')
		permissionsUrls = '/platform/addAdmin';
		$('#editRole').modal();
	})
	function roleList(){
		$('#roleId').empty();
		var data = null;
		var html ='';
		var cbk = function(res){
			for (var i = 0; i < res.data.length; i++) {
				html += '<option value="'+ res.data[i].roleId +'">'+ res.data[i].roleName +'</option>'
			}
			$('#roleId').append(html)
		}
		ajax(
			serverURL + '/platform/queryAdminRoleList',
			data,
			cbk,
			'post',
			'json'
		)
	}
	//编辑
	$(document).on('click', '.editRole', function() {
		var id = $(this).attr('data-id')
		$('#entBtns').attr('data-id',id)
		permissionsUrls = '/platform/updateAdminById';
		$('#editRole').modal();
		var data = {
			'adminId':id
		}
		var cbk = function(res){
			console.log(res)
			$('#adminName').val(res.data.adminName);
			$('#adminPassword').val(res.data.adminPassword);
			$('#roleId').val(res.data.roleId)
		}
		ajax(
			serverURL + '/platform/queryAdminById',
			data,
			cbk,
			'post',
			'json'
		)
	})
	//添加修改
	$('#entBtns').click(function(){
		id = $(this).attr('data-id')
		var password = ''
		if($('#adminPassword').val().length!=32){
			password = md5($('#adminPassword').val())
		}else{
			password = $('#adminPassword').val()
		}
		var data = {
			'adminId':id,
			'adminName':$('#adminName').val(),
			'adminPassword':password,
			'roleId':$('#roleId').val()
		}
		var callback = function(res){
			$('#editRole').modal('hide')
			tableList()
		}
		ajax(
			serverURL + permissionsUrls,
			data,
			callback,
			'post',
			'json',
			false
		)
	})

	$('#editRole').on('hidden.bs.modal', function (e) {
		$("#adminName").val('')
		$("#adminPassword").val('')
	})
</script>
